﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using GameLibrary.Input;

namespace GameLibrary.Tools
{
    public class OutPut
    {
        private static bool reSize;
        private static bool Move;
        private static bool Scroll;

        private static float Scroloffset = 0;
        private static Vector2 Moaseoffset;

        private static int TextSize;
        private static List<string> buffer = new List<string>();
        private static SpriteFont Font;

        private static Rectangle Shape;



        //private static void operator -(string s){
        //    buffer.Add(s);

        //}

        //public static void operator -(int i){
        //    buffer.Add(Convert.ToString( i ));
        //}

        //public static void operator -(float i){
        //    buffer.Add(Convert.ToString( i ));
        //}

        //public static void operator -(bool i){
        //    buffer.Add(Convert.ToString( i ));
        //}

        //public static void operator -(double i){
        //    buffer.Add(Convert.ToString( i ));
        //}
        public static void Out(string s)
        {
            buffer.Add(s);
        }


        public static void Out(int i)
        {
            buffer.Add(Convert.ToString(i));
        }

        public static void Out(float i)
        {
            buffer.Add(Convert.ToString(i));
        }

        public static void Out(double i)
        {
            buffer.Add(Convert.ToString(i));
        }

        public static void Out(Vector2 i)
        {
            string s = Convert.ToString(i.X) + ":" +
                       Convert.ToString(i.Y);
            buffer.Add(s);
        }
        public static void Out(Vector3 i)
        {
            string s = Convert.ToString(i.X) + ":" +
                       Convert.ToString(i.Y) + ":" +
                       Convert.ToString(i.Z);
            buffer.Add(s);
        }

        public static void Out(bool i)
        {
            if (i)
                buffer.Add(Convert.ToString("true"));
            buffer.Add(Convert.ToString("true"));
        }


        public static void inInitializ(Rectangle shape, int textsize, SpriteFont fornt)
        {
            Shape = shape;
            TextSize = textsize;
            Font = fornt;
        }

        public static void Clear()
        {
            buffer.Clear();
        }

        public static void Draw(SpriteBatch spriteBatch, Texture2D dot)
        {
            spriteBatch.Draw(dot, Shape, new Color(25, 20, 10, 30));

            //int diff = buffer.Count - Shape.Height/TextSize;
            //if(diff < 0){
            //  diff = 0;
            //}

            int bufsize = buffer.Count;
            for (int i = 0; i < bufsize; i++)
            {
                float ypos = (Shape.Y + Shape.Height + Scroloffset) - ((bufsize - i) * (Font.LineSpacing));

                if ((ypos > Shape.Y) && (ypos < (Shape.Y + Shape.Height)))
                {



                    spriteBatch.DrawString(Font, buffer[i], new Vector2(Shape.X, ypos), Color.Red);

                }
                //spriteBatch.DrawString(Font, buffer[i], new Vector2(Shape.X, Shape.Y + (i * (TextSize+10))), Color.Red);
            }

            if ((buffer.Count * (Font.LineSpacing)) > Shape.Height)
            {
                Scroloffset += CMouse.ScrollWheelDelta / 10;

                if (Scroloffset < 0) Scroloffset = 0;
                //if (Scroloffset > buffer.Count * (TextSize + 10)) Scroloffset = buffer.Count*(TextSize + 10);
            }
        }
    }
}
